var util = require('../../libs/util.js');
Page({
    data: {
        loaded: false,              // 是否已加载页面
        loadMoreType: 'normal',
        pageLimit: 10,
        pageSize: 1,
        news: []
    },
    onReachBottom: function() {
        if(this.loadMoreType == 'nomore') return;
        this.setData({pageSize: this.getData('pageSize') + 1});
        this.loadList();
    },
    loadList() {
        var _this = this;
        this.setData({loadMoreType: 'refresh'});
        util.request({
            url: 'article.article/lists',
            method: 'POST',
            data: {
                limit: this.getData('pageLimit'),
                page: this.getData('pageSize')
            },
            success: function (res) {
                var news = _this.getData('news');
                if(!_this.getData('loaded')) {
                    _this.setData({loaded: true});
                }
                if(res.result.data.length < _this.getData('pageLimit')) {
                    _this.setData({loadMoreType: 'nomore'});
                }
                _this.setData({news: news.concat(res.result.data)});
            }
        });
    },
    onLoad() {
        swan.showNavigationBarLoading();
        this.loadList();
    },
    onReady: function() {
        swan.hideNavigationBarLoading();
        swan.setNavigationBarTitle({title: '新闻资讯'});
    }
})